#!/usr/bin/env python3
"""
系统配置数据模型
"""

from datetime import datetime

from sqlalchemy.orm import mapped_column, Mapped
from sqlalchemy.sql.sqltypes import Boolean, DateTime, Integer, String, Text

from app.models import Base


class SystemConfig(Base):
    """系统配置表"""

    __tablename__ = "system_configs"

    # 主键
    id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)

    # 配置信息
    config_key: Mapped[str] = mapped_column(String(100), unique=True, index=True, comment="配置键")
    config_value: Mapped[str | None] = mapped_column(Text, nullable=True, comment="配置值")
    config_type: Mapped[str] = mapped_column(String(50), default="string", comment="配置类型")

    # 描述信息
    description: Mapped[str | None] = mapped_column(Text, nullable=True, comment="配置描述")
    is_encrypted: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否加密存储")

    # 系统信息
    created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now, comment="创建时间")
    updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.now, onupdate=datetime.now, comment="更新时间")

    def __repr__(self) -> str:
        return f"<SystemConfig(id={self.id}, config_key='{self.config_key}')>"
